import 'package:flutter/material.dart';
import 'package:xindong/common/xindong_sezhi.dart';
import 'package:xindong/common/xindong_methods.dart';
import 'package:xindong/manager/xindong_page_singleton.dart';
import 'package:xindong/manager/xindong_permission_ctr.dart';
import 'package:xindong/manager/xindong_user_controller.dart';
import 'package:xindong/models/xindong_setting_class.dart';
import 'package:xindong/routes/call/controller/xindong_call_controller.dart';
import 'package:xindong/routes/beauty/xindong_beauty_yemian.dart';
import 'package:xindong/routes/common/xindong_about_yemian.dart';
import 'package:xindong/routes/common/xindong_blacklist_yemian.dart';
import 'package:xindong/routes/common/xindong_destroy_yemian.dart';
import 'package:xindong/routes/common/xindong_password_yemian.dart';
import 'package:xindong/routes/common/xindong_security_yemian.dart';
import 'package:xindong/routes/common/xindong_setting_general_yemian.dart';
import 'package:xindong/routes/common/xindong_setting_money_yemian.dart';
import 'package:xindong/routes/common/xindong_setting_privacy_yemian.dart';
import 'package:xindong/routes/common/xindong_setting_push_yemian.dart';
import 'package:xindong/routes/tab_mine/view/xindong_wode_item_cell.dart';
import 'package:xindong/widgets/common/xindong_app_bar.dart';
import 'package:xindong/widgets/container/xindong_fenzu_container.dart';
import 'package:xindong/widgets/dialog/xindong_alert_message.dart';

class XinDongSettingYeMian extends StatelessWidget {
  const XinDongSettingYeMian({super.key});

  Future<void> onTap(XinDongSettingClass model) async {
    switch (model.type) {
      case SettingType.beauty:
        if (XinDongCallController.to.status != XinDongCallStatus.none) {
          showToast("当前正在通话中");
          return;
        }
        bool havePermission = await XinDongPermissionCtr.checkPermission(XinDongAppPermission.camera);
        if (havePermission) {
          XinDongPageSingleton.instance.pushNoBackYeMian(const XinDongBeautyYeMian());
        }
        break;
      case SettingType.security:
        XinDongPageSingleton.instance.pushYeMian(const XinDongSecurityYeMian());
        break;
      case SettingType.destroy:
        XinDongAlertMessage.show(
          content: "注销账号会清空您的所有的账信息，是否要继续注销？",
          onTapButton: () {
            // 注销账号会清空您的所有的账信息，是否要继续注销？
            XinDongPageSingleton.instance.pushYeMian(const XinDongDestroyYeMian());
          },
        );
        break;
      case SettingType.blacklist:
        XinDongPageSingleton.instance.pushYeMian(const XinDongBlacklistYeMian());
        break;
      // case SettingType.feedback:
      //   Get.toNamed(RouteNames.mineFeedbackYeMian);
      //   break;
      // case SettingType.maskSetting:
      //   Get.toNamed(RouteNames.mineMaskSetting);
      //   break;
      // case SettingType.like:
      //   Get.to(XinDongWoDeLikeYeMian());
      // break;
      case SettingType.clear:
        // AlertOptions.show(
        //   content: '缓存大小：$_cacheSizeText',
        //   buttonTow: "取消",
        //   buttonOne: "清除缓存",
        //   onTabOne: () async {
        //     String size = await XinDongCacheTool.clearCache();
        //     setState(() {
        //       _cacheSizeText = size;
        //     });
        //   },
        //   onTabTow: () {},
        // );
        break;
      case SettingType.money:
        XinDongPageSingleton.instance.pushYeMian(const XinDongSettingMoneyYeMian());
        break;
      case SettingType.about:
        XinDongPageSingleton.instance.pushYeMian(const XinDongAboutYeMian());
        break;
      // case SettingType.notice:
      //   XinDongJumpManager.instance.pushYeMian(const XinDongNoticeYeMian());
      //   break;
      case SettingType.password:
        XinDongPageSingleton.instance.pushYeMian(const XinDongPasswordYeMian());
        break;
      case SettingType.privacy:
        XinDongPageSingleton.instance.pushYeMian(const XinDongSettingPrivacyYeMian());
        break;
      case SettingType.general:
        XinDongPageSingleton.instance.pushYeMian(const XinDongSettingGeneralYeMian());
        break;
      case SettingType.notice:
        XinDongPageSingleton.instance.pushYeMian(const XinDongSettingPushYeMian());
        break;
      // case SettingType.version:
      //   XinDongVersionDialog.checkNeedForceUpgrade();
      //   break;
      case SettingType.logout:
        XinDongAlertMessage.show(
          title: "退出登录",
          content: "你确定要退出登录吗？",
          button: "确定",
          onTapButton: () {
            XinDongUserController.to.userLogout();
          },
        );
        break;
      default:
        break;
    }
  }

  @override
  Widget build(BuildContext context) {
    final dataList = [
      [
        XinDongSettingClass(type: SettingType.beauty, title: "美颜设置"),
      ],
      [
        XinDongSettingClass(type: SettingType.privacy, title: "隐私设置"),
        XinDongSettingClass(type: SettingType.general, title: "通用设置"),
        XinDongSettingClass(type: SettingType.notice, title: "新消息通知"),
        XinDongSettingClass(type: SettingType.blacklist, title: "黑名单"),
      ],
      [
        XinDongSettingClass(type: SettingType.security, title: "账号与安全"),
        // XinDongSettingClass(type: SettingType.password, title: "密码设置"),
        XinDongSettingClass(type: SettingType.destroy, title: "注销账号"),
      ],
      [
        XinDongSettingClass(type: SettingType.about, title: "关于我们"),
      ],
      [
        XinDongSettingClass(type: SettingType.logout, title: "退出当前账号"),
      ]
    ];
    // 女的才有收费设置
    if (XinDongUserController.to.userInfo?.isFemale == true) {
      dataList.insert(0, [XinDongSettingClass(type: SettingType.money, title: "收费设置")]);
    }
    return Scaffold(
      appBar: XinDongAppBar("设置"),
      body: XinDongGroupSectionContainer(
        dataList: dataList,
        padding: const EdgeInsets.only(bottom: 16),
        itemBuilder: (BuildContext context, int section, int index, data) {
          XinDongSettingClass model = data;
          if (model.type == SettingType.logout) {
            return XinDongWoDeTextCenterItemWidget(model: model, onTap: () => onTap(model));
          }
          return XinDongWoDeItemWidget(
            model: model,
            backgroundColor: DZColors.cellColor,
            onTap: () => onTap(model),
          );
        },
      ),
    );
  }
}
